// var i;
// var $uI_BoxLevelInfo_UIBindings = require("./UI_BoxLevelInfo_UIBindings");
// var $uIView = require("./UIView");
// var $hallManager = require("./HallManager");
// var $excel = require("./Excel");
// var d = cc._decorator;
// var p = d.ccclass;
// var h = d.property;
// var f = d.inspector;
// var g = (function (e) {
//     function t() {
//         var t = (null !== e && e.apply(this, arguments)) || this;
//         t.auto_ui = null;
//         t.currLevel = 0;
//         return t;
//     }
//     __extends(t, e);
//     t.prototype._show = function () {
//         this.currLevel = $hallManager.HallMgr.shopData.boxLevel;
//         this.firstBoxData = $excel.Excel.shopBoxLevel(1);
//         this.ShowLevel(this.currLevel);
//     };
//     t.prototype._clickListener = function (e) {
//         switch (e) {
//             case this.auto_ui.btn_closeBtn:
//                 this._close();
//                 break;
//             case this.auto_ui.btn_lastBtn:
//                 this.currLevel--;
//                 this.ShowLevel(this.currLevel);
//                 break;
//             case this.auto_ui.btn_nextBtn:
//                 this.currLevel++;
//                 this.ShowLevel(this.currLevel);
//         }
//     };
//     t.prototype.ShowLevel = function (e) {
//         this.currLevel = e;
//         var t = this.auto_ui;
//         t.txt_levelLbael.string = "LV." + (e + 1);
//         t.btn_lastBtn.node.active = e > 0;
//         t.btn_nextBtn.node.active = e < $excel.Excel.shopBoxLevel_all.size - 1;
//         var o = $excel.Excel.shopBoxLevel(e + 1);
//         t.txt_box1LvLabel.node.parent.active = o.rewards[0] > 0;
//         t.txt_box1LvLabel.string = "+" + (o.rewards[0] - this.firstBoxData.rewards[0]);
//         t.txt_box1LanLabel.node.parent.active = o.rewards[1] > 0;
//         t.txt_box1LanLabel.string = "+" + (o.rewards[1] - this.firstBoxData.rewards[1]);
//         t.txt_box1ZiLabel.node.parent.active = o.rewards[2] > 0;
//         t.txt_box1ZiLabel.string = "+" + (o.rewards[2] - this.firstBoxData.rewards[2]);
//         t.txt_box2LvLabel.node.parent.active = o.bigRewards[0] > 0;
//         t.txt_box2LvLabel.string = "+" + (o.bigRewards[0] - this.firstBoxData.bigRewards[0]);
//         t.txt_box2LanLabel.node.parent.active = o.bigRewards[1] > 0;
//         t.txt_box2LanLabel.string = "+" + (o.bigRewards[1] - this.firstBoxData.bigRewards[1]);
//         t.txt_box2ZiLabel.node.parent.active = o.bigRewards[2] > 0;
//         t.txt_box2ZiLabel.string = "+" + (o.bigRewards[2] - this.firstBoxData.bigRewards[2]);
//     };
//     __decorate([h($uI_BoxLevelInfo_UIBindings.default)], t.prototype, "auto_ui", void 0);
//     return __decorate([p], t);
// })($uIView.default);
// exports.default = g;


// import UI_BoxLevelInfo_UIBindings from "./UI_BoxLevelInfo_UIBindings";
// import UIView from "./UIView";
// import { HallMgrInstance } from "./HallManager";
// import { Excel } from "./Excel";

// const { ccclass, property, inspector } = cc._decorator;

// /**
//  * 建议类名: BoxLevelInfo
//  */
// @ccclass
// class UI_BoxLevelInfo extends UIView {
//     @property(UI_BoxLevelInfo_UIBindings)
//     auto_ui: any = null;

//     currLevel: number = 0;
//     firstBoxData: any = null;

//     /**
//      * 显示当前等级信息
//      * 建议方法名: showCurrentLevelInfo
//      */
//     _show(): void {
//         this.currLevel = HallMgrInstance.shopData.boxLevel;
//         this.firstBoxData = Excel.shopBoxLevel(1);
//         this.ShowLevel(this.currLevel);
//     }

//     /**
//      * 处理按钮点击事件
//      * @param event - 点击事件
//      * 建议方法名: handleButtonClick
//      */
//     _clickListener(event: cc.Button): void {
//         switch (event) {
//             case this.auto_ui.btn_closeBtn:
//                 this._close();
//                 break;
//             case this.auto_ui.btn_lastBtn:
//                 this.currLevel--;
//                 this.ShowLevel(this.currLevel);
//                 break;
//             case this.auto_ui.btn_nextBtn:
//                 this.currLevel++;
//                 this.ShowLevel(this.currLevel);
//                 break;
//         }
//     }

//     /**
//      * 显示指定等级的信息
//      * @param level - 等级
//      * 建议方法名: displayLevelInfo
//      */
//     ShowLevel(level: number): void {
//         this.currLevel = level;
//         const ui = this.auto_ui;
//         ui.txt_levelLbael.string = "LV." + (level + 1);
//         ui.btn_lastBtn.node.active = level > 0;
//         ui.btn_nextBtn.node.active = level < Excel.shopBoxLevel_all.size - 1;

//         const boxData = Excel.shopBoxLevel(level + 1);
//         ui.txt_box1LvLabel.node.parent.active = boxData.rewards[0] > 0;
//         ui.txt_box1LvLabel.string = "+" + (boxData.rewards[0] - this.firstBoxData.rewards[0]);
//         ui.txt_box1LanLabel.node.parent.active = boxData.rewards[1] > 0;
//         ui.txt_box1LanLabel.string = "+" + (boxData.rewards[1] - this.firstBoxData.rewards[1]);
//         ui.txt_box1ZiLabel.node.parent.active = boxData.rewards[2] > 0;
//         ui.txt_box1ZiLabel.string = "+" + (boxData.rewards[2] - this.firstBoxData.rewards[2]);

//         ui.txt_box2LvLabel.node.parent.active = boxData.bigRewards[0] > 0;
//         ui.txt_box2LvLabel.string = "+" + (boxData.bigRewards[0] - this.firstBoxData.bigRewards[0]);
//         ui.txt_box2LanLabel.node.parent.active = boxData.bigRewards[1] > 0;
//         ui.txt_box2LanLabel.string = "+" + (boxData.bigRewards[1] - this.firstBoxData.bigRewards[1]);
//         ui.txt_box2ZiLabel.node.parent.active = boxData.bigRewards[2] > 0;
//         ui.txt_box2ZiLabel.string = "+" + (boxData.bigRewards[2] - this.firstBoxData.bigRewards[2]);
//     }
// }

// export default UI_BoxLevelInfo;

import UIBoxLevelInfoUIBindings from "./UI_BoxLevelInfo_UIBindings";
import UIViewBase from "./UIView";
import { HallMgr } from "./HallManager";
import { Excel } from "./Excel";

const { ccclass, property } = cc._decorator;

/**
 * 建议类名: BoxLevelInfo
 */
@ccclass
class ViewBoxLevelInfo extends UIViewBase {
    @property(UIBoxLevelInfoUIBindings)
    auto_ui: UIBoxLevelInfoUIBindings = null;

    // 当前等级
    currLevel: number = 0;
    // 初始箱子数据
    firstBoxData: any = null;

    /**
     * 显示当前等级信息
     * 建议方法名: showCurrentLevelInfo
     */
    _show(): void {
        this.currLevel = HallMgr.shopData.boxLevel;
        this.firstBoxData = Excel.shopBoxLevel(1);
        this.showLevel(this.currLevel);
    }

    /**
     * 处理按钮点击事件
     * @param clickEvent - 点击事件
     * 建议方法名: handleButtonClick
     */
    _clickListener(clickEvent: cc.Button): void {
        switch (clickEvent) {
            case this.auto_ui.btn_closeBtn:
                this._close();
                break;
            case this.auto_ui.btn_lastBtn:
                this.currLevel = Math.max(0, this.currLevel - 1); // 确保等级不为负
                this.showLevel(this.currLevel);
                break;
            case this.auto_ui.btn_nextBtn:
                this.currLevel = Math.min(Excel.shopBoxLevel_all.size - 1, this.currLevel + 1); // 确保等级不超过最大值
                this.showLevel(this.currLevel);
                break;
        }
    }

    /**
     * 显示指定等级的信息
     * @param level - 等级
     * 建议方法名: displayLevelInfo
     */
    showLevel(level: number): void {
        this.currLevel = level;
        const uiBindings = this.auto_ui;

        uiBindings.txt_levelLbael.string = `LV.${level + 1}`;
        uiBindings.btn_lastBtn.node.active = level > 0;
        uiBindings.btn_nextBtn.node.active = level < Excel.shopBoxLevel_all.size - 1;

        const boxData = Excel.shopBoxLevel(level + 1);
        const firstBoxRewards = this.firstBoxData.rewards;
        const firstBoxBigRewards = this.firstBoxData.bigRewards;

        uiBindings.txt_box1LvLabel.node.parent.active = boxData.rewards[0] > 0;
        uiBindings.txt_box1LvLabel.string = `+${boxData.rewards[0] - firstBoxRewards[0]}`;
        uiBindings.txt_box1LanLabel.node.parent.active = boxData.rewards[1] > 0;
        uiBindings.txt_box1LanLabel.string = `+${boxData.rewards[1] - firstBoxRewards[1]}`;
        uiBindings.txt_box1ZiLabel.node.parent.active = boxData.rewards[2] > 0;
        uiBindings.txt_box1ZiLabel.string = `+${boxData.rewards[2] - firstBoxRewards[2]}`;

        uiBindings.txt_box2LvLabel.node.parent.active = boxData.bigRewards[0] > 0;
        uiBindings.txt_box2LvLabel.string = `+${boxData.bigRewards[0] - firstBoxBigRewards[0]}`;
        uiBindings.txt_box2LanLabel.node.parent.active = boxData.bigRewards[1] > 0;
        uiBindings.txt_box2LanLabel.string = `+${boxData.bigRewards[1] - firstBoxBigRewards[1]}`;
        uiBindings.txt_box2ZiLabel.node.parent.active = boxData.bigRewards[2] > 0;
        uiBindings.txt_box2ZiLabel.string = `+${boxData.bigRewards[2] - firstBoxBigRewards[2]}`;
    }
}

export default ViewBoxLevelInfo;